#!/bin/bash

init() {
    kubectl apply -f pv.yaml
    kubectl create configmap redis-conf --from-file=redis.conf
    kubectl apply -f redis-service.yaml
    kubectl apply -f redis-statefulset.yaml

    kubectl exec -it redis-app-0 -- redis-cli --cluster create --cluster-replicas 1 $(kubectl get pods -l app=redis -o jsonpath='{range.items[*]}{.status.podIP}:6379 ')
}

reset() {
    kubectl delete -f redis-statefulset.yaml
    kubectl delete -f redis-service.yaml
    kubectl delete configmap redis-conf
    kubectl get pvc | grep redis-data | awk '{print $1}' | xargs kubectl delete pvc
    kubectl delete -f pv.yaml
}
